﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Yugi.Client.WebSerive
{
    public class PlayerInfo
    {
        public int ID { get; set; }
        public string Email { get; set; }
        public string Password { get; set; }
        public String NickName { get; set; }
        public int Level { get; set; }
        public int IsOnline { get; set; }
        public List<int> Storage = new List<int>();
        public List<int> Deck = new List<int>();
        public PlayerInfo()
        {
        }
        public PlayerInfo(string input)
        {
            string[] temps = input.Split('|');
            this.ID = Convert.ToInt32(temps[0]);
            this.Level = Convert.ToInt32(temps[1]);
            this.NickName = temps[2];
            this.IsOnline = Convert.ToInt16(temps[3]);
        }
        public static PlayerInfo Deserialize(string s)
        {
            PlayerInfo p = new PlayerInfo();
            string[] temp= s.Split('\n');
            int value;
            foreach (var item in temp[0].Split(','))
            {
                if(Int32.TryParse(item,out value))
                    p.Storage.Add(value);
            }
            foreach (var item in temp[1].Split(','))
            {
                
                if (Int32.TryParse(item, out value))
                    p.Deck.Add(value);
            }
            return p;
        }

        public static List<PlayerInfo> DeSerialization(string input)
        {
            string[] temps = input.Split('\n');
            List<PlayerInfo> res = new List<PlayerInfo>();

            for (int i = 0; i < temps.Length - 1; i++)
            {
                res.Add(new PlayerInfo(temps[i]));
            }
            return res;
        }
    }
    public class TableInfo
    {
        public int TableID { get; set; }
        public int PlayerID1 { get; set; }
        public int PlayerID2 { get; set; }
        public string NickName1 { get; set; }
        public string NickName2 { get; set; }
        public int Payment { get; set; }
        public int CardID { get; set; }
        public string Comment { get; set; }
        public string CardName { get; set; }
        public TableInfo()
        {

        }
        public TableInfo(string input)
        {
            string[] temps = input.Split('|');
            this.TableID = Convert.ToInt32(temps[0]);
            this.PlayerID1 =Convert.ToInt32(temps[1]);
            this.PlayerID2 =Convert.ToInt32(temps[2]);
            this.NickName1 = temps[3];
            this.NickName2 = temps[4];
            this.Payment =Convert.ToInt32(temps[5]);
            this.CardID = Convert.ToInt32(temps[6]);
            this.CardName = temps[7];
            this.Comment = temps[8];
        }
        public override string ToString()
        {
            return String.Format("{0}|{1}|{2}", TableID, NickName1, NickName2);
        }

        //------------------------------STATIC---------------------------------------------//
        public static List<TableInfo> DeSerialization(string input)
        {
            string[] temps= input.Split('\n');
            List<TableInfo> res = new List<TableInfo>();

            for (int i = 0; i < temps.Length-1; i++)
            {
                res.Add(new TableInfo(temps[i]));
            }
            return res;
        }
    }
    public class RoomInfo
    {
        public int RoomID { get; set; }
        public string RoomName { get; set; }
        public int CountUser { get; set; }
        public int CountCreater { get; set; }
        public int Level { get; set; }
        public RoomInfo()
        {

        }
        public RoomInfo(string input)
        {
            string[] temps = input.Split('|');
            this.RoomID = Convert.ToInt32(temps[0]);
            this.RoomName = (temps[1]);
            this.CountUser = Convert.ToInt32(temps[2]);
            this.CountCreater = Convert.ToInt32(temps[3]);
        }
        public override string ToString()
        {
            return String.Format("{0}|{1}|{2}|{3}", RoomID, RoomName, CountUser, CountCreater);
        }

        //------------------------------STATIC---------------------------------------------//
        public static List<RoomInfo> DeSerialization(string input)
        {
            string[] temps = input.Split('\n');
            List<RoomInfo> res = new List<RoomInfo>();

            for (int i = 0; i < temps.Length - 1; i++)
            {
                res.Add(new RoomInfo(temps[i]));
            }
            return res;
        }

    }
    public class CardInfo
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int Total { get; set; }
    }
}
